/*
 * @Author: ducafecat
 * @Description: 列表页
 * @Date: 2018-04-13 16:13:27
 * @Last Modified by: hans.taozhiwei
 * @Last Modified time: 2018-04-13 16:15:33
 */
import {
  list
} from '@/api/hmmm/subjects.js'
import {
  list as userlist
} from '@/api/base/users.js'
const app = {
  state: {
    name: '',
    subjectList: null,
    userList: null

  },
  mutations: {
    SET_NAME: (state, name) => {
      state.name = name
    },
    // 设置学科列表
    SET_SUBJECT(state, data) {
      console.log(data);
      state.subjectList = data
    },
    // 设置用户列表
    SET_USER(state, data) {
      console.log(data);
      state.userList = data
    }
  },
  actions: {
    setName({
      commit
    }, userInfo) {
      const username = userInfo.username.trim()
      return new Promise((resolve, reject) => {
        commit('SET_NAME', username)
        resolve()
      })
    },
    // 获取学科列表
    async getSubject({
      commit
    }, data) {
      try {
        let res = await list(data)

        commit('SET_SUBJECT', res.data.items)


      } catch (error) {

      }
    },
    // 获取用户列表
    async getUser({
      commit
    }, data) {
      try {
        let res = await userlist(data)

        commit('SET_USER', res.data.list)
      } catch (error) {

      }
    }
  }
}

export default app
